//
const { T_question_score } = require('../models/T_question_score')

exports.insertDefaultScore = async function (ACSId) {
    try {

        console.log("fajlahglsaghalghawghawoghawogha合适的话v阿是嘎规划");
        const mes = await T_question_score.findOne({
            where: {
                t_user_and_a_c_s_id: ACSId
            }
        })
        console.log(mes);
        if (!mes) {
            T_question_score.create({
                t_user_and_a_c_s_id: ACSId
            })

        }

    } catch (error) {
        return error.msg
    }
    return null

}
exports.deleteQuestionScore = async function (ACSId) {
    try {
        T_question_score.destroy({
            where: {
                t_user_and_a_c_s_id: ACSId
            }
        })

    } catch (error) {
        return error.msg
    }
    return null

}

exports.getQuestionScore = async (req, res) => {
    const ACSId = req.query.ACSId
    try {
        const scoreMes = await T_question_score.findOne({
            where: {
                t_user_and_a_c_s_id: ACSId
            }
        })

        res.json({
            "code": 200,
            "msg": scoreMes,
        });
    } catch (error) {
        res.json({
            "code": 500,
            "msg": error.msg
        });
    }

}

exports.updateQuestionScore = async (req, res) => {
    const ACSId = req.query.ACSId
    const oneChoiceQuestions = req.query.oneChoiceQuestions
    const multipleChoiceQuestions = req.query.multipleChoiceQuestions
    const fillBlankQuestions = req.query.fillBlankQuestions
    const judgeQuestions = req.query.judgeQuestions
    try {
        const scoreMes = await T_question_score.update({
            oneChoiceQuestions, multipleChoiceQuestions, fillBlankQuestions, judgeQuestions
        }, {
            where: {
                t_user_and_a_c_s_id: ACSId
            }
        })

        res.json({
            "code": 200,
            "msg": scoreMes,
        });
    } catch (error) {
        res.json({
            "code": 200,
            "msg": error.msg
        });
    }
}